home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d13 / nuf210.arc / GETARGS.C < prev    next >
Text File  |  1990-06-14  |  20KB  |  722 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <ctype.h>
  5. #include <dir.h>
  6. #include <dos.h>
  7.  
  8. #include "nufind.h"
  9. #include "queue.h"
  10.  
  11. struct DateSel {
  12.     unsigned        Date;
  13.     int             Swt;
  14.     };
  15.  
  16. char           *RootPath(char *CurDir, char *RelPath, char *FullPath);
  17. void            GetStdIn(QUE_DEF * Que, char *Prompt);
  18. int             GetList(QUE_DEF * Que, char *argv[], int i, char *Prompt, char *PathName);
  19. void            ErrorExit(char *Format,...);
  20. void            ErrorMsg(char *Format,...);
  21. void            ExceptionMsg(char *Format,...);
  22. int             GetAttr(char **Str, int i);
  23. int             MakeDir(char *Name);
  24. int             GetDate(char **argv, int i, struct DateSel * Date);
  25. long            GtoJ(unsigned m, unsigned d, unsigned y);
  26. void            JtoG(long Julian, int *Month, int *Day, int *Year);
  27. int             isdevice(int handle);
  28. int             GetDirRef(char **Ref, char **argv, int i);
  29. int             GetFileRef(INFO_BLOCK ** Ref, char **argv, int i);
  30. void            GetPath(QUE_DEF * Q, char *Arg);
  31. int             GetYorN(char *Message,...);
  32. int                CheckPath (QUE_DEF *Q, char *Name);
  33. void            SetCopyMove (char *argv[], int *i, int *Swt);
  34.  
  35. static char    *OptTable[] = {
  36. #define O_NAME                0
  37.     "name",
  38. #define O_NAME_SHORT        1
  39.     "n",
  40. #define O_NOT_NAME            2
  41.     "^name",
  42. #define O_NOT_NAME_SHORT    3
  43.     "^n",
  44. #define O_FNAME                4
  45.     "fname",
  46. #define O_FNAME_SHORT        5
  47.     "fn",
  48. #define O_NOT_FNAME            6
  49.     "^fname",
  50. #define O_NOT_FNAME_SHORT    7
  51.     "^fn",
  52. #define O_SILENT            8
  53.     "s",
  54. #define O_PRINT                9
  55.     "p",
  56. #define O_LS                10
  57.     "ls",
  58. #define O_LD                11
  59.     "ld",
  60. #define O_REMOVE            12
  61.     "rm",
  62. #define O_REMOVE_ALL        13
  63.     "rma",
  64. #define O_ATTR                14
  65.     "attr",
  66. #define O_NOT_ATTR            15
  67.     "^attr",
  68. #define O_ATTR_ON            16
  69.     "attr+",
  70. #define O_ATTR_OFF            17
  71.     "attr-",
  72. #define O_NO_RECUR            18
  73.     "nr",
  74. #define O_COPY                19
  75.     "cp",
  76. #define O_MOVE                20
  77.     "mv",
  78. #define O_SINCE                21
  79.     "si",
  80. #define O_BEFORE            22
  81.     "be",
  82. #define O_SIZE                23
  83.     "size",
  84. #define O_REMOVE_DIR        24
  85.     "rmdir",
  86. #define O_EXEC                25
  87.     "exec",
  88. #define O_EXEC_SHORT        26
  89.     "ex",
  90. #define O_TREE                27
  91.     "t",
  92. #define O_SUM                28
  93.     "sum",
  94. #define O_EXIST                29
  95.     "exist",
  96. #define O_NOT_EXIST            30
  97.     "^exist",
  98. #define O_COMP                31
  99.     "comp",
  100. #define O_NOT_COMP            32
  101.     "^comp",
  102. #define O_LT                33
  103.     "lt",
  104. #define O_LE                34
  105.     "le",
  106. #define O_GT                35
  107.     "gt",
  108. #define O_GE                36
  109.     "ge",
  110. #define O_LT_DATE            37
  111.     "ltdate",
  112. #define O_LE_DATE            38
  113.     "ledate",
  114. #define O_GT_DATE            39
  115.     "gtdate",
  116. #define O_GE_DATE            40
  117.     "gedate",
  118. #define O_RELATIVE            41
  119.     "re",
  120. #define O_NOT_PATH            42
  121.     "^dir",
  122. #define O_NOT_PATH_SHORT    43
  123.     "^d",
  124. #define O_MOVE_TREE            44
  125.     "mt",
  126. #define O_COPY_TREE            45
  127.     "ct",
  128. #define O_COPY_TREE_DATE    46
  129.     "cto",
  130. #define O_COPY_DATE            47
  131.     "cpo",
  132. #define O_KILL                48
  133.     "kill",
  134. #define O_INVALID            49
  135.     ""
  136.     };
  137.  
  138.  
  139.  void
  140. GetArgs (char *argv[], int i) {
  141.     extern QUE_DEF  Paths, ExcPaths;
  142.     extern QUE_DEF  IncNameQueue, ExcNameQueue;
  143.     extern QUE_DEF  IncPathQueue, ExcPathQueue;
  144.     extern char     DestDir[], CurDir[];
  145.     extern int      PrtSwt, LsSwt, LdSwt, RmSwt, RmSwtA, AttrSwt, NotAttrSwt;
  146.     extern int      AttrOnSwt, AttrOffSwt, RecurSwt, CopySwt, MoveSwt, RmDirSwt;
  147.     extern int      SizeSwt, ExecSwt, TreeSwt, SumSwt, RelSwt, OldDate;
  148.     extern char     AttrMask, NotAttrMask, AttrOnMask, AttrOffMask;
  149.     extern char    *ExistRef, *NotExistRef, *CompRef, *NotCompRef;
  150.     extern INFO_BLOCK *LT_Ref, *LE_Ref, *GT_Ref, *GE_Ref;
  151.     extern INFO_BLOCK *LT_DateRef, *LE_DateRef, *GT_DateRef, *GE_DateRef;
  152.     extern char    *CommandString;
  153.     extern unsigned TodayDate;
  154.     extern long     Size;
  155.     extern struct DateSel Since, Before;
  156.  
  157.     char           *Arg, PathName[65];
  158.     int             j;
  159.  
  160.     for (; argv[i] != NULL; ++i) {
  161.         if (**(argv + i) != '-') continue;
  162.         Arg = (*(argv + i)) + 1;
  163.  
  164.         for (j = 0; OptTable[j][0] != '\0'; ++j)
  165.             if (!strcmp(Arg, OptTable[j])) break;
  166.  
  167.         switch (j) {
  168.             case O_NOT_PATH:
  169.             case O_NOT_PATH_SHORT:
  170.                 for (++i; argv[i] != NULL && argv[i][0] != '-'; ++i)
  171.                     GetPath(&ExcPaths, argv[i]);
  172.                 if (argv[i][0] == '-') --i;
  173.                 break;
  174.             case O_NAME:
  175.             case O_NAME_SHORT:
  176.                 i = GetList(&IncNameQueue, argv, i, "-name:", NULL);
  177.                 continue;
  178.             case O_NOT_NAME:
  179.             case O_NOT_NAME_SHORT:
  180.                 i = GetList(&ExcNameQueue, argv, i, "-^name:", NULL);
  181.                 continue;
  182.             case O_FNAME:
  183.             case O_FNAME_SHORT:
  184.                 i = GetList(&IncPathQueue, argv, i, "-fname:", PathName);
  185.                 continue;
  186.             case O_NOT_FNAME:
  187.             case O_NOT_FNAME_SHORT:
  188.                 i = GetList(&ExcPathQueue, argv, i, "-^fname:", PathName);
  189.                 continue;
  190.             case O_SILENT:
  191.                 PrtSwt = 0;
  192.                 break;
  193.             case O_PRINT:
  194.                 PrtSwt |= 0x02;
  195.                 break;
  196.             case O_LS:
  197.                 LsSwt = 1;
  198.                 PrtSwt &= 0xFE;
  199.                 break;
  200.             case O_LD:
  201.                 LdSwt = 1;
  202.                 PrtSwt &= 0xFE;
  203.                 break;
  204.             case O_REMOVE:
  205.                 RmSwt = 1;
  206.                 PrtSwt &= 0xFE;
  207.                 break;
  208.             case O_REMOVE_ALL:
  209.                 RmSwtA = 1;
  210.                 PrtSwt &= 0xFE;
  211.                 break;
  212.             case O_REMOVE_DIR:
  213.                 RmDirSwt = 1;
  214.                 PrtSwt &= 0xFE;
  215.                 break;
  216.             case O_ATTR:
  217.                 AttrMask = GetAttr(argv, ++i);
  218.                 AttrSwt = 1;
  219.                 break;
  220.             case O_NOT_ATTR:
  221.                 NotAttrMask = GetAttr(argv, ++i);
  222.                 NotAttrSwt = 1;
  223.                 break;
  224.             case O_ATTR_ON:
  225.                 AttrOnMask = GetAttr(argv, ++i);
  226.                 PrtSwt &= 0xFE;
  227.                 AttrOnSwt = 1;
  228.                 break;
  229.             case O_ATTR_OFF:
  230.                 AttrOffMask = GetAttr(argv, ++i);
  231.                 PrtSwt &= 0xFE;
  232.                 AttrOffSwt = 1;
  233.                 break;
  234.             case O_NO_RECUR:
  235.                 RecurSwt = 0;
  236.                 break;
  237.             case O_COPY_TREE_DATE:
  238.                 OldDate = 1;
  239.             case O_COPY_TREE:
  240.                 TreeSwt = 1;
  241.                 SetCopyMove(argv, &i, &CopySwt);
  242.                 break;
  243.             case O_COPY_DATE:
  244.                 OldDate = 1;
  245.             case O_COPY:
  246.                 SetCopyMove(argv, &i, &CopySwt);
  247.                 break;
  248.             case O_MOVE_TREE:
  249.                 TreeSwt = 1;
  250.                 RmDirSwt = 1;
  251.                 SetCopyMove(argv, &i, &MoveSwt);
  252.                 break;
  253.             case O_MOVE:
  254.                 SetCopyMove(argv, &i, &MoveSwt);
  255.                 break;
  256.             case O_SINCE:
  257.                 i = GetDate(argv, i, &Since);
  258.                 break;
  259.             case O_BEFORE:
  260.                 i = GetDate(argv, i, &Before);
  261.                 break;
  262.             case O_SIZE:
  263.                 if ( argv[i + 1][0] == '\0'
  264.                     || (argv[i + 1][0] == '-' && !isdigit(argv[i + 1][1])) )
  265.                     ErrorExit("\"%s\" Size argument required.\n", argv[i]);
  266.                 else if (isdigit(argv[i + 1][0])) {
  267.                     Size = atol(argv[++i]);
  268.                     SizeSwt = 1;
  269.                     }
  270.                 else if (argv[i + 1][0] == '-' && isdigit(argv[i + 1][1])) {
  271.                     Size = atol(argv[++i] + 1);
  272.                     SizeSwt = 2;
  273.                     }
  274.                 else
  275.                     ErrorExit("\"%s\" Invalid size - %s\n", argv[i],
  276.                               argv[i + 1]);
  277.                 break;
  278.             case O_EXEC:
  279.             case O_EXEC_SHORT:
  280.                 if (argv[i + 1][0] == '\0' || argv[i + 1][0] == '-')
  281.                     ErrorExit("\"%s\" Command required.\n", argv[i]);
  282.                 ExecSwt = 1;
  283.                 PrtSwt &= 0xFE;
  284.                 CommandString = strdup(argv[++i]);
  285.                 break;
  286.             case O_TREE:
  287.                 TreeSwt = 1;
  288.                 break;
  289.             case O_SUM:
  290.                 SumSwt = 1;
  291.                 break;
  292.             case O_EXIST:
  293.                 i = GetDirRef(&ExistRef, argv, i);
  294.                 break;
  295.             case O_NOT_EXIST:
  296.                 i = GetDirRef(&NotExistRef, argv, i);
  297.                 break;
  298.             case O_COMP:
  299.                 i = GetDirRef(&CompRef, argv, i);
  300.                 break;
  301.             case O_NOT_COMP:
  302.                 i = GetDirRef(&NotCompRef, argv, i);
  303.                 break;
  304.             case O_LT:
  305.                 i = GetFileRef(<_Ref, argv, i);
  306.                 break;
  307.             case O_LE:
  308.                 i = GetFileRef(&LE_Ref, argv, i);
  309.                 break;
  310.             case O_GT:
  311.                 i = GetFileRef(>_Ref, argv, i);
  312.                 break;
  313.             case O_GE:
  314.                 i = GetFileRef(&GE_Ref, argv, i);
  315.                 break;
  316.             case O_LT_DATE:
  317.                 i = GetFileRef(<_DateRef, argv, i);
  318.                 break;
  319.             case O_LE_DATE:
  320.                 i = GetFileRef(<_DateRef, argv, i);
  321.                 break;
  322.             case O_GT_DATE:
  323.                 i = GetFileRef(>_DateRef, argv, i);
  324.                 break;
  325.             case O_GE_DATE:
  326.                 i = GetFileRef(&GE_DateRef, argv, i);
  327.                 break;
  328.             case O_RELATIVE:
  329.                 RelSwt = 1;
  330.                 break;
  331.             case O_KILL:
  332.                 RmSwt = 1;
  333.                 RmDirSwt = 1;
  334.                 PrtSwt &= 0xFE;
  335.                 break;
  336.             default:
  337.                 ErrorExit("Invalid option: %s", Arg);
  338.             }
  339.         }
  340.     }
  341.  
  342.  
  343.  int
  344. GetList (QUE_DEF * Que, char *argv[], int i, char *Prompt, char *PathName) {
  345.     extern char     CurDir[];
  346.  
  347.     FILE           *F1;
  348.     char            Line[80];
  349.  
  350.     if (!strcmp(argv[i + 1], "-")) {
  351.         GetStdIn(Que, Prompt);
  352.         ++i;
  353.         }
  354.     else if (argv[i + 1][0] == '@') {
  355.         if ((F1 = fopen(&argv[i + 1][1], "r")) == NULL)
  356.             ErrorExit("I can't find index file: %s!\n", &argv[i + 1][1]);
  357.         while (fgets(Line, 79, F1) != NULL) {
  358.             if (Line[strlen(Line) - 1] == '\n') Line[strlen(Line) - 1] = '\0';
  359.             else ErrorExit("Index file: %s - Line too long\n %s\n",
  360.                             &argv[i + 1][1], Line);
  361.             if (PathName != NULL) {
  362.                 if ((Enque(Que, strlwr(RootPath(CurDir, Line, PathName))))
  363.                     == NULL) {
  364.                     ErrorMsg("Insufficient memory for input list.\n");
  365.                     return (i);
  366.                     }
  367.                 }
  368.             else if ((Enque(Que, strlwr(Line))) == NULL) {
  369.                 ErrorMsg("Insufficient memory for input list.\n");
  370.                 return (i);
  371.                 }
  372.             }
  373.         fclose(F1);
  374.         i += 1;
  375.         }
  376.     else {
  377.         for (++i; argv[i] != NULL && argv[i][0] != '-'; ++i)
  378.             if (PathName != NULL) {
  379.                 if ((Enque(Que, strlwr(RootPath(CurDir, argv[i], PathName))))
  380.                     == NULL) {
  381.                     ErrorMsg("Insufficient memory for input list.\n");
  382.                     return (i);
  383.                     }
  384.                 }
  385.             else if ((Enque(Que, strlwr(argv[i]))) == NULL) {
  386.                 ErrorMsg("Insufficient memory ofr input list.\n");
  387.                 return (i);
  388.                 }
  389.         --i;
  390.         }
  391.     return (i);
  392.     }
  393.  
  394.  void
  395. GetStdIn (QUE_DEF *Que, char *Prompt) {
  396.     char            Line[80];
  397.  
  398.     while (1) {
  399.         if (isdevice(fileno(stdin))) fprintf(stderr, "%s ", Prompt);
  400.         if (gets(Line) == NULL) break;
  401.         if (Line[0] == '\0') break;
  402.         if ((Enque(Que, Line)) == NULL) {
  403.             ErrorMsg("Insufficient memory for input lst.\n");
  404.             return;
  405.             }
  406.         }
  407.     }
  408.  
  409.  int
  410. GetAttr (char **Str, int i) {
  411.     char            Ch;
  412.     int             j, Mask;
  413.  
  414.     if (Str[i][0] == '\0' || Str[i][0] == '-')
  415.         ErrorExit("\"%s\" must be followed by a list of attributes.", Str[i - 1]);
  416.     Mask = j = 0;
  417.     while ((Ch = tolower(Str[i][j++])) != '\0') switch (Ch) {
  418.         case 'r':
  419.             Mask |= 0x01;
  420.             break;
  421.         case 'h':
  422.             Mask |= 0x02;
  423.             break;
  424.         case 's':
  425.             Mask |= 0x04;
  426.             break;
  427.         case 'v':
  428.             Mask |= 0x08;
  429.             break;
  430.         case 'd':
  431.             Mask |= 0x10;
  432.             break;
  433.         case 'a':
  434.             Mask |= 0x20;
  435.             break;
  436.         default:
  437.             ErrorExit("\"%s\" Invalid attribute: %s", Str[i - 1], Str[i]);
  438.         }
  439.     return (Mask);
  440.     }
  441.  
  442.  
  443.  int
  444. MakeDir (char *Name) {
  445.     extern QUE_DEF    NoCreateQ;
  446.     struct ffblk    DirBlk;
  447.     char           *p, Temp[66];
  448.     int             Result;
  449.  
  450.     if (NoCreateQ.Count != 0)
  451.         if ( CheckPath(&NoCreateQ, Name) != 0 ) return(0);
  452.     p = strrchr(Name, '\\');
  453.     if (*(p - 1) == ':') return (0);
  454.     *p = '\0';
  455.     Result = findfirst(Name, &DirBlk, 0xFF);
  456.     if (Result || (DirBlk.ff_attrib & FA_DIREC) == 0) {
  457.         if ((Result = MakeDir(Name)) != 0) return (Result);
  458.         if ( !GetYorN("Directory %s does not exist.  Create it ", Name) ) {
  459.             strcpy(Temp, Name);
  460.             strcat(Temp, "\\*");
  461.             Enque(&NoCreateQ, Temp);
  462.             return(2);
  463.             }
  464.         if ((Result = mkdir(Name)) == 0) {
  465.             strcpy(Temp, Name);
  466.             strcat(Temp, "\\*");
  467.             Enque(&ExcPathQueue, Temp);
  468.             }
  469.         else {
  470.             strcpy(Temp, Name);
  471.             strcat(Temp, "\\*");
  472.             Enque(&NoCreateQ, Temp);
  473.             }
  474.         }
  475.     *p = '\\';
  476.     return (Result);
  477.     }
  478.  
  479.  int
  480. GetDate (char **argv, int i, struct DateSel * Date) {
  481.     unsigned long   Today;
  482.     int             Arg1, Arg2, Arg3;
  483.     int             Year, Month, Day;
  484.     char           *p, Temp[3], *Str;
  485.  
  486.     if ( (argv[i + 1] == NULL) || (argv[i + 1][0] == '\0')
  487.         || (argv[i + 1][0] == '-' && !isdigit(argv[i + 1][1]))) {
  488.         Date->Date = TodayDate;
  489.         Date->Swt = 1;
  490.         return (i);
  491.         }
  492.     if (argv[i + 1] != NULL && isdigit(argv[i + 1][0])) {
  493.         Str = argv[++i];
  494.         p = &Str[strcspn(Str, "-/")];
  495.         if (*p != 0) {
  496.             *p = '\0';
  497.             Arg1 = atoi(Str);
  498.             Str = ++p;
  499.             p = &Str[strcspn(Str, "-/")];
  500.             if (*p == '\0')
  501.                 ErrorExit("\"%s\" Invalid date - %s\n", argv[i - 1], argv[i]);
  502.             *p = '\0';
  503.             Arg2 = atoi(Str);
  504.             Arg3 = atoi(p + 1);
  505.             }
  506.         else if (strlen(Str) > 2) {
  507.             strncpy(Temp, Str, 2);
  508.             Temp[2] = '\0';
  509.             Arg1 = atoi(Temp);
  510.             strncpy(Temp, Str + 2, 2);
  511.             Temp[2] = '\0';
  512.             Arg2 = atoi(Temp);
  513.             strncpy(Temp, Str + 4, 2);
  514.             Temp[2] = '\0';
  515.             Arg3 = atoi(Temp);
  516.             }
  517.         else {
  518.             Today = GtoJ((TodayDate >> 5) & 0x0F, TodayDate & 0x1F,
  519.                          (TodayDate >> 9) & 0x7F);
  520.             i = atoi(Str);
  521.             JtoG(Today - i, &Arg1, &Arg2, &Arg3);
  522.             Arg3 += 80;
  523.             }
  524.         if (Arg1 > 31) {
  525.             Year = Arg1;
  526.             Month = Arg2;
  527.             Day = Arg3;
  528.             }
  529.         else {
  530.             Year = Arg3;
  531.             Month = Arg1;
  532.             Day = Arg2;
  533.             }
  534.         if (Month > 12 || Day > 31)
  535.             ErrorExit("\"%s\" Invalid date - %s\n", argv[i - 1], argv[i]);
  536.         if (Year > 100) Year -= 1980;
  537.         else Year -= 80;
  538.         }
  539.     Date->Date = (Year << 9) | (Month << 5) | Day;
  540.     Date->Swt = 1;
  541.     return (i);
  542.     }
  543.  
  544. /************************************************************************/
  545. /*                *** GtoJ.c ***                                          */
  546. /*                                                                        */
  547. /* This function converts a gregorian date, in the ( month, day, year )    */
  548. /* format, into its respective julian, or day number, equivalent.        */
  549. /* ( 1 = 1st day AD )                                                    */
  550. /*                                                                        */
  551. /* The legal input values, in their proper order, are:                    */
  552. /*                                                                        */
  553. /* month   =  1   to    12            ( unsigned int )                    */
  554. /* day     =  1   to    31            ( unsigned int )                    */
  555. /* year    =  0   to  9999            ( unsigned int )                    */
  556. /*                                                                        */
  557. /* The return value of the function is the julian day number            */
  558. /* expressed as    an unsigned long integer.                                */
  559. /*                                                                        */
  560. /************************************************************************/
  561.  
  562.  long
  563. GtoJ (unsigned m, unsigned d, unsigned y) {
  564.  
  565.     y += (m += 9) / 12 + 399;
  566.     m %= 12;
  567.     return ((long) y * 365 + y / 4 - y / 100 + y / 400 + (153 * m + 2) / 5 + d - 146037L);
  568.     }
  569.  
  570. /************************************************************************/
  571. /*                *** JtoG.c ***                                          */
  572. /*                                                                        */
  573. /* This function converts a julian day number ( 1 = 1st day AD ), into    */
  574. /* either a gregorian date character string, in any one of the four        */
  575. /* formats described below, or an array of three integers representing    */
  576. /* the month, day, and year, respectively, of the equivalent gregorian    */
  577. /* date.  Storage for the output is provided by the calling routine.    */
  578. /*                                                                        */
  579. /* The input values, in their proper order, are:                        */
  580. /*                                                                        */
  581. /* 1.  the julian date to be converted,          ( unsigned long )            */
  582. /*                                                                        */
  583. /* 2.  a pointer to the output array,              ( char * )            */
  584. /*                                                                        */
  585. /* 3.  the format code ( described below )                                */
  586. /* specifying the desired output format.          ( unsigned int )        */
  587. /*                                                                        */
  588. /* The format codes are defined as follows:                                */
  589. /*                                                                        */
  590. /* CODE            - EXPLANATION -                                            */
  591. /*                                                                        */
  592. /* 0  -  output array will hold three integers defined as:                */
  593. /*                                                                        */
  594. /* array[0] = month    (   mm )                                            */
  595. /* array[1] = day        (   dd )                                        */
  596. /* array[2] = Year     ( yyyy )                                            */
  597. /*                                                                        */
  598. /* If this format option is used, a type cast will have to                */
  599. /* be performed on the output pointer to convert it to the                */
  600. /* appropriate pointer type. ( see example below )                        */
  601. /*                                                                        */
  602. /* 1  -  output string will hold a character string in the                */
  603. /* format "mmddyy"      ( minimum - char string[7] )                        */
  604. /*                                                                        */
  605. /* 2  -  output string will hold a character string in the                */
  606. /* format "mmddyyyy"      ( minimum - char string[9] )                    */
  607. /*                                                                        */
  608. /* 3  -  output string will hold a character string in the                */
  609. /* format "mm/dd/yy"      ( minimum - char string[9] )                    */
  610. /*                                                                        */
  611. /* 4  -  output string will hold a character string in the                */
  612. /* format "mm/dd/yyyy"  ( minimum - char string[11] )                    */
  613. /*                                                                        */
  614. /* NOTE -  input of any format code not listed above will be            */
  615. /* interpreted as code 0.                                                */
  616. /*                                                                        */
  617. /* The function returns a character pointer to the output array.        */
  618. /* _________________________________________________________________    */
  619. /* |       *** example of integer array output ***                    |    */
  620. /* |                                                                |    */
  621. /* |  int Month, dte_array[3];                                      |    */
  622. /* |  long    julian = 548784;                                        |    */
  623. /* |                                                                |    */
  624. /* |  Month = ( (int *)JtoG( Julian, (char *)dte_array, 0 ) )[0];    |   */
  625. /* |________________________________________________________________|    */
  626. /*                                                                        */
  627. /* WARNING -  the output array pointed to must be dimensioned            */
  628. /* accordingly or a memory overwrite will occur.                        */
  629. /************************************************************************/
  630.  
  631.  void
  632. JtoG (long Julian, int *Month, int *Day, int *Year) {
  633.  
  634.     *Year = (int) ((Julian += 146037L) * 400 / 146097L);
  635.     Julian -= (long) *Year * 365 + *Year / 4 - *Year / 100 + *Year / 400;
  636.     if (!Julian) Julian = 365 + !(*Year % 4), --*Year;
  637.     *Year += (*Month = (*Day = (int) Julian * 5 - 3) / 153 + 2) / 12 - 400;
  638.     *Month = *Month % 12 + 1;
  639.     *Day = *Day % 153 / 5 + 1;
  640.     }
  641.  
  642.  
  643. /*
  644.  * ISDEVICE - Will invoke Ms-Dos IOCTL function to "get" the attributes of
  645.  * the specified DOS handle.
  646.  *
  647.  * Result := True     If the specified handle is a device.
  648.  *          := False      If the specified handle is a file.
  649.  *
  650.  * Caution: A True return only indicates that the handle is assigned to a device
  651.  * driver.  These include the CON, PRN, AUX and any user installed device
  652.  * drivers.
  653.  *
  654.  * A False return indicates that the handle is assigned to a file that may be on
  655.  * a Floppy, Hard Disk or Ram Disk.
  656.  */
  657.  
  658.  
  659.  int
  660. isdevice (int handle) {
  661.     union REGS      R;
  662.  
  663.     R.x.ax = 0x4400;            /* MS-DOS IOCTL "Get" function */
  664.     R.x.bx = handle;            /* ... Handle for IOCTL "Get"  */
  665.     R.x.dx = 0;
  666.     intdos(&R, &R);                /* ... MS-DOS Entry Interrupt  */
  667.     if ((R.x.dx & 0x80) == 0) return (0);
  668.     else return (1);
  669.     }
  670.  
  671.  
  672.  int
  673. GetDirRef (char **Ref, char **argv, int i) {
  674.  
  675.     if (argv[i + 1][0] == '\0' || argv[i + 1][0] == '-')
  676.         ErrorExit("\"%s\" requires a directory argument.", argv[i]);
  677.     if ((*Ref = malloc(66)) == NULL)
  678.         ErrorMsg("Insufficient memory for \"%s\".", argv[i]);
  679.     else RootPath(CurDir, argv[++i], *Ref);
  680.     return (i);
  681.     }
  682.  
  683.  int
  684. GetFileRef (INFO_BLOCK **Ref, char **argv, int i) {
  685.     struct ffblk    DirBlk;
  686.  
  687.     if (argv[i + 1][0] == '\0' || argv[i + 1][0] == '-')
  688.         ErrorExit("\"%s\" requires a filename argument.", argv[i]);
  689.     if ((*Ref = malloc(sizeof(INFO_BLOCK))) == NULL)
  690.         ErrorMsg("Insufficient memory for \"%s\" reference.", argv[i]);
  691.     else {
  692.         RootPath(CurDir, argv[++i], (*Ref)->Name);
  693.         if (findfirst((*Ref)->Name, &DirBlk, (FA_SYSTEM | FA_RDONLY | FA_HIDDEN | FA_ARCH)))
  694.             ErrorExit("\"%s\" - %s", argv[i - 1], argv[i]);
  695.         (*Ref)->Attrib = DirBlk.ff_attrib;
  696.         (*Ref)->FTime.Time = DirBlk.ff_ftime;
  697.         (*Ref)->FDate.Date = DirBlk.ff_fdate;
  698.         (*Ref)->Size = DirBlk.ff_fsize;
  699.         }
  700.     return (i);
  701.     }
  702.  
  703.  
  704.  void
  705. SetCopyMove (char *argv[], int *i, int *Swt) {
  706.     char *p;
  707.  
  708.     if (argv[*i + 1] == NULL || argv[*i + 1][0] == '-')
  709.         strcpy(DestDir, CurDir);
  710.     else if ( !strcmp(argv[*i + 1], ".") ) strcpy(DestDir, CurDir);
  711.     else if ( !strcmp(argv[*i + 1], "..") ) {
  712.         CurDir[strlen(CurDir)-1] = '\0';
  713.         *(p = strrchr(CurDir, '\\')) = '\0';
  714.         strcpy(DestDir, CurDir); strcat(DestDir, "\\");
  715.         *p = '\\';
  716.         strcat(CurDir, "\\");
  717.         }
  718.     else RootPath(CurDir, argv[++*i], DestDir);
  719.     *Swt = 1;
  720.     PrtSwt &= 0xFE;
  721.     }
  722.